package cn.com.utt.unms.mapper;

import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import cn.com.utt.unms.pojo.City;
import cn.com.utt.unms.pojo.District;
import cn.com.utt.unms.pojo.Province;

@Mapper
public interface AddressMapper {

	@Select("select * from province order by count")
	List<Province> queryAllProvinces();

	@Select("select * from district where cityId=#{id} order by count")
	List<District> getDistrictByCityId(@Param("id") long id);

	@Select("select * from city where provinceId=#{id} order by count")
	List<City> getCityByProvinceId(@Param("id") long id);
	
	@Select({"<script>",
		"select province.name as name,province.vn_id as id,ifnull(value,0) as value from province left join (select location.province,count(device.id) as value from network left join location on network.location_id = location.id left join device on device.network_id = network.id where network.id IN", 
	      "<foreach item='item' index='index' collection='networkIds'",
	      "open='(' separator=',' close=')'>",
	       "#{item}",
	     "</foreach> group by `network_id`) a on province.id = a.province",
	"</script>"})
	List<Map<String, Object>> getMapByNetwork(@Param("networkIds")List<Long> networkIds);
}